Contents
  1. 1. 固件模拟
    1. 1.1. 固件解包
    2. 1.2. sys-mod(failed
  2. 2. 分析
    1. 2.1. 目标文件分析
  3. 3. exp
  4. 4. 最后

影响版本:v1.12之前

固件下载地址:https://tsd.dlink.com.tw/ 选择下载DIR-878 v1.12 & v1.04

漏洞详情:https://www.seebug.org/vuldb/ssvid-97802

固件模拟

固件解包

和以前的固件直接解包不太一样,v1.12是加密了的固件版本,而从图中可以看出,v1.10是第一个加密的版本且v1.04还未加密。

这种类型属于设备固件出厂时未加密,也不包含任何解密例程。解密例程与固件的未加密版本(v1.04)一起以更高版本(v1.10)一起提供,以用于将来的加密固件更新,随后的固件版本将被加密。在这个方案中,我们可以从固件v1.04获取解密例程,并使用它来解密新的固件v1.12版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ binwalk DIR878A1_FW1.12B01_Encrypt.bin 

DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------

# 被加密
$ binwalk DIR878A1_FW104B05_Middle_FW_Unencrypt.bin

DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 uImage header, header size: 64 bytes, header CRC: 0xC41C48E6, created: 2018-02-03 10:12:31, image size: 10448690 bytes, Data Address: 0x81001000, Entry Point: 0x81611F40, data CRC: 0x64113D8A, OS: Linux, CPU: MIPS, image type: OS Kernel Image, compression type: lzma, image name: "Linux Kernel Image"
160 0xA0 LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 15907264 bytes
68516 0x10BA4 MySQL MISAM index file Version 6

# 未加密
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ binwalk -Me DIR878A1_FW104B05_Middle_FW_Unencrypt.bin 
$ cd _DIR878A1_FW104B05_Middle_FW_Unencrypt.bin.extracted/_A0.extracted/_8AB758.extracted/cpio-root
# 进入了根目录
$ find ./ -name *crypt*
...
./bin/imgdecrypt
# 找到了
$ file ./bin/imgdecrypt
./bin/imgdecrypt: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld-uClibc.so.0, stripped
# 文件为LSB 小端 mipsel
$ cp $(which qemu-mipsel-static) ./
# 将DIR878A1_FW1.12B01_Encrypt.bin粘贴到根目录后再解密,否则无效
$ sudo chroot ./ ./qemu-mipsel-static ./bin/imgdecrypt ./DIR878A1_FW1.12B01_Encrypt.bin
key:C05FBF1936C99429CE2A0781F08D6AD8
# 输出了key 解密成功,再移回到原来的目录下
1
2
$ binwalk -Me DIR878A1_FW1.12B01_Encrypt.bin 
# 然后一样的 到根目录去...

sys-mod(failed

1
2
3
4
5
6
7
8
$ sudo guestmount -a debian_wheezy_mipsel_standard.qcow2 -m /dev/sda1 /mnt
$ sudo cp -rf ./cpio-root/ /mnt/root/
$ sudo guestunmount /mnt

$ sudo tunctl -t tap0 -u `whoami`
$ sudo ifconfig tap0 192.168.65.1/24

$ sudo qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0" -net nic -net tap,ifname=tap0,script=no,downscript=no -nographic

乌鱼子…模拟不起来…😭

在公网上也没有找到可用的路由器…

直接分析吧…

分析

目标文件分析

根据漏洞详情,定位到目标文件librcm.so中的目标函数tw_add_url_filter_iptables_rule

可以发现存在命令注入

流程为load_iptables -> upload_url_filter_rules -> tw_add_url_filter_iptables_rule & tw_add_url_allow_filter_iptables_rule

在twsystem函数中

查找一下上面tw_add_url_filter_iptables_rule引用处,注意到了下面有一个差不多的函数,都一样的。

exp

在站点过滤处,修改站点URL\域,需要注意url的预处理过程,函数会根据/来截取域名,所以不要用/…

前端无法注入,使用burp抓包修改即可。

最后

在DIR-878路由器中,还有很多类似的命令注入如CVE-2019-8317\8318\8319(漏洞在/bin/rc中),都是由twsystem完成,程序对很多输入并没有进行过滤或检测。

以后分析要更透彻才行哦…

Reference

D-Link路由器HNAP协议系列漏洞披露

https://github.com/lieanu/vuls/blob/master/dlink/DIR-878/webfilter.md

路由器加密固件的解密